<template>
  <div class="tenantMenu_main main_container">
    <div class="main_header">
      <div class="padding_container">
        <div class="left"><Breadcrumb /></div>
        <div class="right">
          <HeaderOperation :parent="this" />
        </div>
      </div>
    </div>
    <div v-loading="loading" class="main_main">
      <SearchBar :parent="this" />
      <div ref="table_container" class="table_container">
        <el-table
          ref="table"
          :data="tableData"
          stripe
          border
          :height="tableHeight"
          style="width: 99.9%"
          :cell-style="cellStyle"
          @sort-change="(column)=>{sortChange(column, this)}"
          @selection-change="(val)=>{selectionChange(val, this)}"
        >
          <el-table-column label="空间状态" min-width="100">
            <template slot-scope="scope">
              <div v-if="scope.row.spaceStatus=='1'" class="adequate_space">
                <svg-icon icon-class="通过" />
                空间充足
              </div>
              <div v-if="scope.row.spaceStatus=='2'" class="insufficient_space">
                <svg-icon icon-class="不足" />
                空间不足
              </div>
              <div v-if="scope.row.spaceStatus=='3'" class="full_space">
                <svg-icon icon-class="驳回" />
                空间已满
              </div>
            </template>
          </el-table-column>
          <Column v-for="(column,index) in tableColumns" :key="index" :prop="column.prop" :is-show="column.isShow" :label="column.label" :sortable="column.sortable" :width="column.width" />
          <el-table-column label="操作" align="center" fixed="right" width="120">
            <template slot-scope="scope">
              <el-button
                type="text"
                @click.stop="dilatation(scope.row)"
              >扩容</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="main_bottom">
      <pagination
        :total="total"
        :page.sync="pageData.pageNum"
        :limit.sync="pageData.pageSize"
        :selected-num="selectionsAll.length"
        @pagination="getList"
      />
    </div>

  </div>
</template>

<script>
import { list, configKey } from '@/api/superManage/diskSpaceMonitoring'
import { mapGetters } from 'vuex'
import Column from '@/components/JLink/common/Column.vue'
import AddOrUpdate from './AddOrUpdate.vue'
export default {
  name: 'Index',
  components: { Column },
  computed: {
    ...mapGetters([
      'companyId'
    ])
  },
  data() {
    return {
      loading: false,
      pageId: '磁盘空间监控', // 页面唯一标识
      pageData: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'updateTime',
        isAsc: 'desc'
      },
      warningValue: '',
      total: 1, // 数据一共有多少条
      mainId: 'id', // 表格行ID
      tableHeight: '0', // 表格高度
      tableData: [], // 表格数据
      tableColumns: [], // 表格实际用的字段
      searchColumns: [], // 搜索区实际用的字段
      selections: [], // 表格当前页所选中的行
      selectionsAll: [], // 表格所有页选中的行
      companyOptions: [],
      defaultTableColumns: [// 表格常规字段（初始值）
        { prop: 'companyName', label: '公司名称' },
        { prop: 'contacts', label: '联系人' },
        { prop: 'phone', label: '联系方式' },
        { prop: 'usedSpace', label: '已用空间' },
        { prop: 'freeSpace', label: '剩余空间', canOrder: false },
        { prop: 'space', label: '总空间' },
        { prop: 'lastUpdateTime', label: '最近更新时间', canOrder: false },
        { prop: 'lastUpdatePerson', label: '最近更新人', canOrder: false }
      ],
      defaultSearchColumns: [// 搜索区常规字段（初始值）
        { prop: 'companyName', label: '公司名称', type: 'input' },
        { prop: 'spaceStatus', label: '空间状态', type: 'select', optionsName: 'spaceStatus' }
      ],
      spaceStatus: [
        { value: undefined, label: '全部' },
        { value: '1', label: '空间充足' },
        { value: '2', label: '空间不足' },
        { value: '3', label: '空间已满' }
      ],
      operationData: [ // 右上角的操作按钮
        { label: '预警值', perm: '' },
        { label: '页面配置', perm: '' }
      ]

    }
  },
  created() {
    this.getConfigKey()
  },
  mounted() {
    this.$nextTick(() => {
      this.tableHeight = this.$refs.table_container.offsetHeight
    })
  },
  methods: {
    getConfigKey() {
      configKey().then(res => {
        this.warningValue = res.data['sys.space.restrict']
      })
    },
    cellStyle({ row, column }) {
      if (column.property == 'usedSpace') {
        if (row.spaceStatus == '3') {
          return {
            color: '#F56C6C'
          }
        } else {
          return {
            color: '#333'
          }
        }
      }
      if (column.property == 'freeSpace') {
        if (row.spaceStatus == '2' || row.spaceStatus == '3') {
          return {
            color: '#F56C6C'
          }
        } else {
          return {
            color: '#333'
          }
        }
      }
    },
    dilatation(row) {
      this.$layer.iframe({// 弹框
        content: {
          content: AddOrUpdate, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {
            companyId: row.companyId,
            freeSpace: row.freeSpace
          }// props
        },
        area: ['880px', '700px'],
        title: '空间扩容', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    },
    getList() {
      this.loading = true
      list({ ...this.pageData }).then(res => {
        console.log(res)
        this.tableData = res.data
        this.total = res.total
        this.$nextTick(() => {
          this.setSelectRow(this)// 设置行选中
        })
      }).finally(() => {
        this.loading = false
      })
    },
    refresh() {
      this.pageData.pageNum = 1
      this.getList()
    }
  }
}
</script>

  <style lang="less" scoped>
    .adequate_space{
        color: #19BE6B;
        background-color:rgb(223, 249, 241) ;
        border-radius: 3px;
        max-width: 120px;
        padding: 3px;
        text-align: center;
    }
    .insufficient_space{
        color: #FF9900;
        background-color:rgb(255, 244, 237) ;
        border-radius: 3px;
        max-width: 120px;
        padding: 3px;
        text-align: center;
    }
    .full_space{
        color: #F56C6C;
        background-color:rgb(255, 235, 236) ;
        border-radius: 3px;
        max-width: 120px;
        padding: 3px;
        text-align: center;
    }
  </style>

